package cn.bdqn.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MybatisUtil {
    private static SqlSessionFactory sessionFactory;

    private static SqlSessionFactory getSessionFactory() {
        if(sessionFactory==null){
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            sessionFactory = builder.build(MybatisUtil.class.getClassLoader().getResourceAsStream("mybatis-config.xml"));
        }
        return sessionFactory;
    }

    public static SqlSession getSqlSession() {
        return getSessionFactory().openSession();
    }
}
